#include "winmain.h"
//ctor
CWinmain::CWinmain()
{
};
//dtor
CWinmain::~CWinmain()
{
};
//window callback function definition
LRESULT CALLBACK CWinmain::WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	// declare device contex and paint structure variables
	HDC devicecontext;
	PAINTSTRUCT paintstructure;

	switch(msg) // switch depending on window message
	{
		case WM_DESTROY: // if the X is pressed on the top right of the window, close it.
			PostQuitMessage(0);
			break;

		case WM_PAINT: // if there's drawing to be done, do it.
			devicecontext = BeginPaint (hWindow, &paintstructure);
			EndPaint(hWindow, &paintstructure);
		break;

	default:
		return DefWindowProc(hWindow, msg, wParam, lParam);//return the default window procc if nothing happens
	}
	return 0;
};
// window initialization function definition
HRESULT CWinmain::InitWindow(HINSTANCE hInstance, int nCmdShow)
{
	// setup the window class and register it
	WNDCLASSEX wndcex;
	wndcex.cbSize 			= sizeof(WNDCLASSEX);
	wndcex.style 			= CS_HREDRAW | CS_VREDRAW;
	wndcex.lpfnWndProc 		= WndProc;
	wndcex.cbClsExtra 		= 0;
	wndcex.cbWndExtra 		= 0;
	wndcex.hInstance 		= hInstance;
	wndcex.hIcon 			= LoadIcon(hInstance, NULL);
	wndcex.hCursor 			= LoadCursor(NULL, IDC_ARROW);
	wndcex.hbrBackground 	= (HBRUSH)(COLOR_WINDOW+1);
	wndcex.lpszMenuName 	= NULL;
	wndcex.lpszClassName 	= L"NaughtsAndCrosses";
	wndcex.hIconSm 			= LoadIcon(wndcex.hInstance, NULL);

	// if registering the class fails, return false
	if(!RegisterClassEx(&wndcex))
		return E_FAIL;

	
	// create a rectangle placeholder for the window & adjust it 
	RECT rectangle = {0, 0, 800, 600};
	AdjustWindowRect(&rectangle, WS_OVERLAPPEDWINDOW, FALSE);
	// create the window
	hWindow = CreateWindow(
					L"NaughtsAndCrosses",
					L"Naughts and Crosses",
					WS_OVERLAPPEDWINDOW,
					CW_USEDEFAULT, CW_USEDEFAULT,
					rectangle.right - rectangle.left,
					rectangle.bottom - rectangle.top,
					NULL, NULL, hInstance, NULL);
	// if the window doesn't create return false and close
	if(!hWindow)
		return E_FAIL;
	// show the window if creation is succesfull
	ShowWindow(hWindow, nCmdShow);
	// return true if everything runs properly
	return S_OK;
};
